const webimhandler = require('../../utils/webim_handler');

const { doLogin, getUserInfoWidthCredentials, getUserInfo } = require('../../../common/utils/ws/wsxcx-opendata-sdk');
Page({
  getUserInfoWith(e) {
    const event = e;
    doLogin().then(res => { // 分享出去会41009
      getUserInfoWidthCredentials(event).then((res) => {
      getUserInfo()
        .then((res) => {
        console.log('getUserInfo',res);
          webimhandler.setNickName(res.nickName, function (ret) {
            if (ret.errCode) {
              console.log('修改昵称失败', ret);
            } else {
              console.log('修改昵称成功');
            }
        wx.navigateBack({});  
          });
        })
        .catch((e) => {
        console.error('getUserInfo catch error:', e);
        wx.showModal({
          title: '系统提示',
          content:'授权失败',
          showCancel: false,
              success: (result) => {
                wx.navigateBack({});
              },
            });
          });
      }).catch(err => {
        console.log('======getUserInfoWidthCredentials', err);
      });
    }).catch(err => {
      console.log('======doLogin', err);
    });
  },
});
